package exercise;

import java.util.Random;
import java.util.Scanner;

public class ApiDay01 {
    public static void main(String[] args) {
        String line = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random random = new Random();
        Scanner scan = new Scanner(System.in);
        System.out.println("输入你所需要的验证码长度：");
        int len = scan.nextInt();
        scan.nextLine();// 清除输入缓冲区中的换行符
        String code = "";
        for (int i=0;i<len;i++){
            int num = random.nextInt(line.length());
            char c = line.charAt(num);
            code = code+c;
        }
        System.out.println("验证码："+code);
        System.out.println("请输入你的验证码：");
        String answer = scan.nextLine();
        if(code.equalsIgnoreCase(answer)){
            System.out.println("验证码正确！！！！");
        }else {
            System.out.println("验证码错误！！！请重新输入！！！");
        }
    }
}
